<template>
  <div class="list-page">
    <tool-bar nav="" title="K8s同步设置">
      <el-button @click="add_click()">添加</el-button>
    </tool-bar>
    <my-list
        ref="list"
        url="/sys/k8s-sync-setting/list"
        @param="preload"
        @loaded="procData"
        :page-size="10"
        :query="$data.query"
    >
      <el-table-column align="center" label="配置名称" >
        <template v-slot="scope">
           <el-tag  v-if="scope.row.isActive" effect="dark" type="primary" class="link" @click="edit_click(scope.row)"> {{ scope.row.name }}</el-tag>
          <div v-else class="link" @click="edit_click(scope.row)"> {{ scope.row.name }}</div>
        </template>
      </el-table-column>

      <el-table-column align="center" label="uatHost" >
        <template v-slot="scope">
          {{scope.row.uatServer?.host}}
        </template>

      </el-table-column>
      <el-table-column align="center" label="prodHost" >
        <template v-slot="scope">
          {{scope.row.prodServer?.host}}
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template v-slot="scope">
          <el-button type="primary" plain round @click="set_click(scope.row)" size="small"
                     v-if="!scope.row.isActive">
            激活当前项
          </el-button>
          <el-tag effect="dark" type="primary" v-else style="margin:12px;">当前为激活项</el-tag>
          <el-button type="warning" plain round @click="delete_click(scope.row)" size="small">
            删除
          </el-button>


        </template>
      </el-table-column>
      <template #query="scope">
      </template>
    </my-list>
  </div>
</template>

<script setup>
/**
 * Created by CodeGenerator at 2024-09-02 02:19:55
 */



//定义 vue2的this,当前组件
let $self = getCurrentInstance();

//定义 $attrs
let $attrs = useAttrs()


//定义事件
let $emit = defineEmits(["update:modelValue","loaded"]);

//定义属性
var $props = defineProps({});

//定义data
let $data = reactive({
  //默认查询条件,默认存储
  query:{},
})

const set_click = function(row) {
  var url = "/sys/k8s-sync-setting/set-active?id=" + row.id
  jv.$http.post(url).then(res => {
    top.location.reload();
  })
};

/**
 * 添加查询参数，修改分页参数等。
 * @param param
 */
const preload = (param) => {
  //param.type = this.$route.params.type
}

/**
 * 处理列表的数据
 * @param res
 */
const procData =   (res) => {
  res.data.data.forEach(it => {
    //如果是组合实体，设置 it.id=...
  });
}

const list = ref();

/**
 * 查询列表
 * @param pageNumber
 */
const loadData = (pageNumber) => {
  list.value.loadData(pageNumber);
}

const add_click = () => {
  jv.$router.push("/sys/k8s-sync-setting/add")
}

const edit_click = (row) => {
  //记录上次点击行
  let rowId = row.id;
  list.value.setLastRow(row);
  jv.$router.push("/sys/k8s-sync-setting/edit/" + rowId)
}

const delete_click = async (row) => {
  let rowId = row.id,rowName = row.name;
  await jv.confirm('确认删除 ' + rowName + ' 吗？');

  let res = await jv.$http.post("/sys/k8s-sync-setting/delete/" + rowId)
  loadData();
}


</script>

<style scoped lang="scss">
</style>
